<%- include('css') %>
<link rel="stylesheet" href="/public/js_module/simditor/css/simditor.css">
<div id="app" style="width:980px">
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
        <legend>案件转交</legend>
    </fieldset>

    <form class="layui-form" action="" lay-filter="form">

        <div class="layui-form-item">
            <label class="layui-form-label">转移街道</label>
            <div class="layui-input-block">
                <select name="street_id" id="street_id" lay-verify="required" lay-search="" lay-filter="finduser">
                    <option value="" >直接选择或搜索选择</option>
                    <!--<option :value="item.id" v-for="(item,index) in streets" :key="index">{{item.name}}</option>-->
                </select>
            </div>
        </div>
        <div class="layui-form-item" style="margin-bottom: 400px;">
            <label class="layui-form-label">转移道路</label>
            <div class="layui-input-block">
                <select name="road_id" id="road_id" lay-verify="required" lay-search="" lay-filter="user">
                    <option value="" >直接选择或搜索选择</option>
                    <!--<option :value="item.id" v-for="(item,index) in streets" :key="index">{{item.name}}</option>-->
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit="" v-bind:disabled="isButtonDisabled" lay-filter="save">确认转交</button>
                <button type="button" v-on:click="doclose" class="layui-btn layui-btn-primary">关闭</button>
            </div>
        </div>
    </form>
</div>

<%- include('script') %>
<!--<script src="/public/js_module/jquery.js"></script>-->
<!--simditor富文本依赖-->
<script src="/public/js_module/simditor/module.js"></script>
<script src="/public/js_module/simditor/hotkeys.js"></script>
<script src="/public/js_module/simditor/uploader.js"></script>
<script src="/public/js_module/simditor/simditor.js"></script>

<script>


    var vm = new Vue({
        el: '#app',
        data:function(){
            return {
                isButtonDisabled:false,
                streets:[]
            }

        },
        mounted:function(){
            
            var self = this;
           // this.getroads();
            layui.use(['form'], function () {
                var form = layui.form;
                 self.getstreets(form);
                //监听提交
                form.on('submit(save)', function (data) {
                    self.isButtonDisabled = true;
                    data.field.event_id='<%=id%>';
                    $.get(
                        '/admin/event/flow',
                        {
                            event_id:data.field.event_id,
                            street_id: data.field.street_id,
                            road_id: data.field.road_id,
                        },
                        function(rs){
                            if (rs.code === '200') {
                                parent.vm.iframesave()
                                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                parent.layer.close(index); //再执行关闭  
                                parent.layer.msg('转移成功!')
                                    
                            } else {
                                parent.layer.msg(rs.msg);
                            }
                            self.isButtonDisabled = false;
                        }
                    )
                    return false;
                });
                form.on('select(finduser)',function (data) {
                    console.log(data.value);
                    $('#identity_id').html('<option value="">直接选择或搜索选择</option>');
                    self.getroads(form,data.value);
                });
            });

        },
        
        methods:{

            doclose:function(){
                parent.vm.iframeclose();
                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引         
                parent.layer.close(index); //再执行关闭 
            },
            getstreets:function(form){
                $.get('/admin/street/getlist',(res)=>{
                    if(res.code == 200){
                        this.streets = res.data;
                        console.info(res.data)
                        for (var i = 0; i < res.data.length; i++) {
                            $('#street_id').append(`<option value="${ res.data[i].id}">${ res.data[i].name}</option>`);
                            form.render('select');
                        }
                    }
                });
            },
            getroads:function (form,id) {
                $.get('/admin/event/getroads',{street_id:id},function (res) {
                        $('#road_id').empty();
                        if(res.code == '201'){
                            $('#road_id').append(`<option value="">请先选择转移街道</option>`);
                        }else if(res.code == '200'){
                            var road = res.data;
                            if(road.length>0){
                                $('#road_id').append(`<option value="">请选择转移道路</option>`);
                                for (var i = 0; i < road.length; i++) {
                                    $('#road_id').append(`<option value="${road[i].id}">${road[i].name}</option>`);
                                }
                            }else{
                                $('#road_id').append(`<option value="">无关联道路</option>`);
                            }
                        }
                        form.render('select');
                    }
                )
            }
        }
    })



    
</script>